package Pattern.FactoryPattern.dynamic;

import Pattern.FactoryPattern.dynamic.impl.BuyHouseImpl;
import Pattern.FactoryPattern.dynamic.impl.DynamicProxyHandler;
import org.junit.Test;

import java.lang.reflect.Proxy;

/**
 * @author:MJS
 * @create: 2023-02-02-15:34
 * @description:
 */
public class TestBuyHouse {
    @Test
    public void testBuyHouse(){
        BuyHouse buyHouse = new BuyHouseImpl();
        BuyHouse proxyBuyHouse = (BuyHouse) Proxy.newProxyInstance(BuyHouse.class.getClassLoader(), new Class[]{BuyHouse.class}, new DynamicProxyHandler(buyHouse));
        proxyBuyHouse.buyHouse();
    }

    @Test
    public void testBuyHouse2(){
        BuyHouse2 target = new BuyHouse2();
        cglibProxy cglibProxy = new cglibProxy(target);
        BuyHouse2 proxyInstance = (BuyHouse2) cglibProxy.getProxyInstance();
        proxyInstance.buyHouse();

    }

}
